#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

int main() {
	int n, m;
	cin >> n;
	int a = INF, b = -INF;
	while (n--) {
		int l, r;
		cin >> l >> r;
		a = min(a, r);
		b = max(b, l);
	}
	cin >> m;
	int res = 0;
	while (m--) {
		int l, r;
		cin >> l >> r;
		if (b > r) {
			res = max(res, b - r);
		}
		if (a < l) {
			res = max(res, l - a);
		}
	}
	cout << res << endl;
	return 0;
}